package com.db.router.strategy;

import com.db.router.DBRouterConfig;
import com.db.router.context.DBContextHolder;

import javax.annotation.Resource;

public abstract class DBRouterStrategyBase {

    @Resource
    protected DBRouterConfig dbRouterConfig;


    public void setDBKey(int dbIdx) {
        DBContextHolder.setDBKey(String.format("%02d", dbIdx));
    }

    public void setTBKey(int tbIdx) {
        DBContextHolder.setTBKey(String.format("%03d", tbIdx));
    }

    public int dbCount() {
        return dbRouterConfig.getDbCount();
    }

    public int tbCount() {
        return dbRouterConfig.getTbCount();
    }

    public void clear(){
        DBContextHolder.clearDBKey();
        DBContextHolder.clearTBKey();
    }

}
